// 检测是否是手机
export function is_moblie() {
  return (
    navigator.userAgent
      .toLowerCase()
      .match(
        /(ipod|ipad|iphone|android|coolpad|mmp|smartphone|midp|wap|xoom|symbian|j2me|blackberry|wince)/i
      ) != null
  );
}

// 是否在微信
export function is_weixin() {
  var ua = navigator.userAgent.toLowerCase();
  if (ua.match(/MicroMessenger/i) == 'micromessenger') {
    return true;
  } else {
    return false;
  }
}

export function formatDateTime(inputTime) {
  var date = new Date(inputTime);
  var y = date.getFullYear();
  var m = date.getMonth() + 1;
  m = m < 10 ? '0' + m : m;
  var d = date.getDate();
  d = d < 10 ? '0' + d : d;
  var h = date.getHours();
  h = h < 10 ? '0' + h : h;
  var minute = date.getMinutes();
  var second = date.getSeconds();
  minute = minute < 10 ? '0' + minute : minute;
  second = second < 10 ? '0' + second : second;
  return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
}

// 时间格式化
export function fmtTime(time) {
  let yy = new Date(time).getFullYear();
  let mm = new Date(time).getMonth() + 1;
  let dd = new Date(time).getDate();
  let hh = new Date(time).getHours();
  let mf = new Date(time).getMinutes();
  let ss = new Date(time).getSeconds();
  if (hh < 10) {
    hh = '0' + hh;
  }
  if (mf < 10) {
    mf = '0' + mf;
  }
  if (ss < 10) {
    ss = '0' + ss;
  }
  return `${yy}-${mm}-${dd} ${hh}:${mf}:${ss}`;
}


// 获取浮点数的小数位数
function getPrecision(num) {
  const str = String(num);
  const decimalIndex = str.indexOf('.');
  return decimalIndex === -1 ? 0 : str.length - decimalIndex - 1;
}
// 加法运算
export function addNums(a, b) {
  const precision = Math.max(getPrecision(a), getPrecision(b));
  const multiplier = Math.pow(10, precision);
  return (Math.round(a * multiplier) + Math.round(b * multiplier)) / multiplier;
}


// 乘法运算
export function multiply(a, b) {
  const precision = getPrecision(a) + getPrecision(b);
  const multiplier = Math.pow(10, precision);
  return (Math.round(a * multiplier) * Math.round(b * multiplier)) / (multiplier * multiplier);
}

// 减法运算
export function subtract(a, b) {
  return add(a, -b);
}
// 除法运算
export function divide(a, b) {
  const precision = getPrecision(a) - getPrecision(b);
  const divisor = Math.pow(10, precision);
  return (Math.round(a / b * divisor)) / divisor;
}

//stripe支付
// import { loadStripe } from '@stripe/stripe-js';
export async function payForStripe(vm) {
  const stripe = await loadStripe(
    'pk_test_51OWBuOHZsN7yjioa2OSV71AoeNpkZiXI2H1CJiLWRNIJpJ9HALAtBJUHhhOfekhFWCNZOiWNKGLiuhUgLVicuWcx00mnj69Eep'
  );
  const res = await apiStripePay({});
  console.log(res, 'xxxxxxxxxxxxxx')
  if (!res) {
    stripe.redirectToCheckout({ sessionId: 'https://checkout.stripe.com/c/pay/cs_test_a1jhmbSU7sSn8zboN7oA21vtFHchuCANx50ndLQyVkmGORAbuDM7XYlujQ#fidqdXFsaGx2cWxmUmRpaWBxV2BrYWB3Jz9xd3BgKSdkdWxOYHwnPyd1blpxYHZxWjA0SlJHcEpNX3ZLMnxvbGpkN0pWUzI0RGpgS3VuX2xdTDdNNEZPbElSV0tMT3VPPE1ESURxR09QTW1tSmNgbm1DUkZLX0psUktOQklscG1QYklTbGZwUmZ9NTVoa28zPEBgdScpJ2N3amhWYHdzYHcnP3F3cGApJ2lkfGpwcVF8dWAnPyd2bGtiaWBabHFgaCcpJ2BrZGdpYFVpZGZgbWppYWB3dic%2FcXdwYHgl -' });
  }
}



// 生成唯一标识
const S4 = function () {
  return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
};
export const guid = (S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4());
